<?php              
include "includes".DIRECTORY_SEPARATOR."start_session.php";

if ( !defined('USERNAME') || !defined('GROUP') || GROUP != "admin" )
{
	header("Location: manage_login.php");
	exit;
}
include "javascript".DIRECTORY_SEPARATOR."js_functions.php";
$tablou = array("corNcTypeD" => "",
				"denumireCorNcD" => "",
				"codCorNcD" => "",
				 );
	
$color = array("corNcTypeD" => "#333333",
				"denumireCorNcD" => "#333333",
				"codCorNcD" => "#333333" );	
$corNcVal = array("...","Cor", "Nomenclator", "Ocupatie");
								 		
$erorid = "";

$tablou_erori = array("corNcTypeD" => "Nu a fost introdus tipul<br />",
				"denumireCorNcD" => "Nu a fost introdus denumirea ocupatiei<br />",
				"codCorNcD" => "Nu a fost introdus codul ocupatiei<br />",
				"codCorNcD1D" => "Codul introdus este incorect<br />"
			 );
   
$form_get=<<<GATA
   <form method = POST action = "admin_manage_cor_nc.php">
   <table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
   <tr height="35">
   </tr>
	<tr>
		<td><b>Denumire</b></td>
		<td><input type="text" name="denumireCorNcD" id="denumireCorNcD" size="50" maxsize="150" placeholder="Exe: Inspector"/></td>
	</tr>
	<tr>
		<td><b>Cod</b></td>
		<td><input type="text" name="codCorNcD" id="codCorNcD" size="50" placeholder="Exe: 71411"/></td>
	</tr>
   <tr><td></td><td><input type ="submit" value = "Sterge" ></td></tr>
   <tr><td><input  type="hidden" name="delCorNc" ></td></tr>
   </table>
   </form>
GATA;


if($_SERVER['REQUEST_METHOD'] == 'GET')
{
	echo $form_get;
}

if($_SERVER['REQUEST_METHOD'] == 'POST') 
{
 if ( isset($_POST['delCorNc']) )
{
	$ok = 1;

	if(empty($_POST["denumireCorNcD"]))
	{
			$erorid = $erorid.$tablou_erori["denumireCorNcD"];
			$ok = 0;
			$color["denumireCorNcD"] = "red";
	}
	else $tablou["denumireCorNcD"] =$_POST["denumireCorNcD"] ;
		
	if (empty($_POST["codCorNcD"])){
		$erorid = $erorid.$tablou_erori["codCorNcD"];
		$ok = 0;
		$color["codCorNcD"] = "red";
	}
	else 
		if((preg_match('/^[0-9]+([.][0-9]+)*$/',$_POST["codCorNcD"])) == 0)
		{
			$erorid = $erorid.$tablou_erori["codCorNcD1"];
			$ok = 0;		
			$color["codCorNcD"] = "red";								
		}
		else $tablou["codCorNcD"] =$_POST["codCorNcD"] ;
				
							
	if($ok != 1)
	{
		$corNcTypeD_options = "";
		foreach ($corNcVal as $t)
   			if( $tablou['corNcTypeD'] == $t )
				$corNcTypeD_options = $corNcTypeD_options."<option selected=\"selected\" value='$t'>$t</option>";
			else
				$corNcTypeD_options = $corNcTypeD_options."<option value='$t'>$t</option>";
				 
	   $form_post=<<<GATA
	   <form method = POST action = "admin_manage_cor_nc.php">
	   <table border="0" width="100%" cellspacing="3" cellpadding="3" align="center">
		<tr>
			<td><b><font color='$color[denumireCorNcD]'>Denumire</b></td>
			<td><input value='$tablou[denumireCorNcD]'   type="text" name="denumireCorNcD" id="denumireCorNcD" size="50" maxsize="150" placeholder="Exe: Inspector"/></td>
		</tr>
		<tr>
			<td><b><font color='$color[codCorNcD]'>Cod</b></td>
			<td><input value='$tablou[codCorNcD]'  type="text" name="codCorNcD" id="codCorNcD" size="50" placeholder="Exe: 71411"/></td>
		</tr>
	   <tr><td></td><td><input type ="submit" value = "Sterge" ></td></tr>
	   <tr><td><input  type="hidden" name="delCorNc" value="true" ></td></tr>
	   </table>
	   </form>
			  
GATA;
		echo $form_post;
		echo "<font color=\"red\">".$erorid."</font>";
		}
		else  
		{
			require_once ('mysql_connect.php');
			//"Cor", "Nomenclator", "Ocupatie"
			$u = mysqli_query($dbc,"DELETE FROM `nc` where `denumire`='$tablou[denumireCorNcD]' and `cod`='$tablou[codCorNcD]'");
			$u = mysqli_query($dbc,"DELETE FROM `cor` where `denumire`='$tablou[denumireCorNcD]' and `cod`='$tablou[codCorNcD]'");	
			
			//echo "<br />";	
			echo "<center><h3><font color=\"#00CC00\">Ocupatia a fost stearsa cu succes ! </font></h3></center>";
			echo $form_get;
		}
		
}
else
{
		echo $form_get;
}
}
					
?>


